<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>测试测试</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <style>
        #master {

            position: absolute;

            left: 50%;

            bottom: 0;

            text-align: center;

        }
    </style>
</head>

<body>
    <h1 style="text-align: center;">测试网页1111111</h1>
    <button onclick="test_func()">发起支付请求</button>
    <div id="result"></div>
    <div id="master">


        <a href="http://beian.miit.gov.cn/">
            <center>鄂ICP备2023003600号-2</center>
        </a>

    </div>
</body>
<script>
    const searchParams = new URLSearchParams(window.location.search);
    const code = searchParams.get('code');
    let call_payment_data = {}
    if (code) {
        $.ajax({
            url: 'http://120.25.166.156:8001/test/',
            type: 'POST',
            data: {
                'code': code
            },
            dataType: 'json',
            success: function (data) {
                console.log(data.data);
                call_payment_data = data.data
                $('#result').html(data)

            }
        })
    }
    function test_func() {
        if (typeof WeixinJSBridge == "undefined") {
            if (document.addEventListener) {
                document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
            } else if (document.attachEvent) {
                document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
                document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
            }
        } else {
            onBridgeReady();
        }

    }

    function onBridgeReady() {
        WeixinJSBridge.invoke('getBrandWCPayRequest', call_payment_data,
            function (res) {
                console.log(res);
                if (res.err_msg == "get_brand_wcpay_request:ok") {
                    // 使用以上方式判断前端返回,微信团队郑重提示：
                    //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠，商户需进一步调用后端查单确认支付结果。
                }
            });
    }
</script>

</html>